package com.example.administrator.xjscc;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.utils.Child;
import com.example.utils.MyExpandableListViewAdapter1;
import com.example.utils.Group;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/12/25.
 */

public class MileGatherActivity extends Activity {
    private ArrayList<Group> groups=new ArrayList<Group>();
    private ExpandableListView listView;
    private MyExpandableListViewAdapter1 adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_milegather);

        InitListView();

        listView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i1, long l) {
                TextView tv=(TextView)view.findViewById(R.id.tv_item);
                Intent tmpi=new Intent();
                tmpi.putExtra("workid",tv.getText().toString());
                tmpi.setClass(MileGatherActivity.this,MileGatherResultActivity.class);
                startActivity(tmpi);
                return false;
            }
        });
    }

    private void InitListView()
    {
        GetOrganizeData();
        listView = (ExpandableListView) findViewById(R.id.expList_Comp);
        adapter = new MyExpandableListViewAdapter1(MileGatherActivity.this, groups);
        listView.setAdapter(adapter);
        listView.setOnChildClickListener(adapter);
    }
    /** 解悉 JSON 字串 */
    private void GetOrganizeData() {

        List<HashMap<String, String>> workgroup = new ArrayList<HashMap<String, String>>();

        HashMap<String,String> map=new HashMap<>();
        map.put("groupid","1");
        map.put("groupname","加油组");
        workgroup.add(map);

        map=new HashMap<>();
        map.put("groupid","2");
        map.put("groupname","测试组");
        workgroup.add(map);

        for(Map<String,String> q :workgroup)
        {
            Group g=new Group(q.get("groupid"), q.get("groupname"));
                for(int i=0;i<5;i++)
                {
                    Child c=new Child(q.get("groupid")+i, "work"+i);
                    g.addChildrenItem(c);
                }
            groups.add(g);
        }
    }
}
